package com.guang.interupt;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author lg
 * @Description 线程中断正在运行的线程
 * @date 2022/10/17 11:37
 *
 *
 * 总结：中断正在运行的线程的时候，线程仍然可以运行。
 *      但是线程中断标记将会携带一生！所以不要忘记了将其进行重置！
 */
public class ThreadInteruptTwo {

    private static Logger logger = LoggerFactory.getLogger(ThreadInteruptTwo.class);

    public static void main(String[] args) {
        Thread normalThread = new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()){
                logger.info("当前的线程状态是：{}",Thread.currentThread().isInterrupted());
            }
            if (Thread.currentThread().isInterrupted()){
                logger.info("当前线程已经被中断");
                logger.info("当前的线程状态是：{}",Thread.currentThread().isInterrupted());
            }
            if (Thread.interrupted()){
                logger.info("当前线程已经被中断，需要将其重置为false");
            }
        }, "normal");
        normalThread.start();
        normalThread.interrupt();
    }
}
